package com.zzh.myapplication.manager;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import net.icarplus.car.R;
import net.icarplus.car.tools.DialogUtils;
import net.icarplus.car.tools.PromptDialog;

/**
 * 项目名称：icarplus-car-android
 * 类描述：
 * 创建人：Gophy
 * 创建时间：16/3/1 10:38
 * 修改人：Gophy
 * 修改时间：16/3/1 10:38
 * 修改备注：
 */
public abstract class BaseActivity extends AppCompatActivity implements View.OnClickListener {

    private PromptDialog alertDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getAppManager().addActivity(this);
        setContent();
        initComponent();
        setListener();
        onAfterInit();
    }


    public abstract void setContent();

    public abstract void initComponent();

    public abstract void setListener();

    public abstract void onAfterInit();


    public void start_Activity(Intent intent) {
        startActivity(intent);
        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
    }


    /**
     * 打开Activity, 伴随动画
     *
     * @param intent
     */
    public void start_ActivityForResult(Intent intent, int requestCode) {
        startActivityForResult(intent, requestCode);
        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
    }


    /**
     * 打开Activity, 伴随动画
     *
     * @param intent
     */
    public void start_Activity_RightInForResult(Intent intent, int requestCode) {
        startActivityForResult(intent, requestCode);
        overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
    }

    /**
     * 关闭Activity, 伴随动画
     *
     * @param intent
     */
    public void finish_Activity() {
        finish();
        overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
    }

    /**
     * 关闭Activity, 伴随动画
     *
     * @param intent
     */
    public void finish_ActivityLeftIn() {
        finish();
        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
    }

    /**
     * 显示对话框
     *
     * @param title
     * @param message
     * @param positiveListener
     * @param negativeListener
     */
    public void showAlerDialog(String title, String message,
                               PromptDialog.OnClickListener positiveListener, PromptDialog.OnClickListener negativeListener) {
        if (alertDialog != null) {
            alertDialog.dismiss();
            alertDialog = null;
        }
        alertDialog = DialogUtils.getConfirmDialog(BaseActivity.this, title, message, positiveListener, negativeListener);
    }

    /**
     * 显示对话框
     *
     * @param title
     * @param message
     * @param positiveListener
     * @param negativeListener
     */
    public void showAlerDialog(String title, String message, PromptDialog.OnClickListener positiveListener) {
        if (alertDialog != null) {
            alertDialog.dismiss();
            alertDialog = null;
        }
        alertDialog = DialogUtils.getDefaultDialog(BaseActivity.this, title, message, positiveListener);
    }
}
